<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\TagRequest;
use App\Model\Tag;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class TagController extends CommonController
{

    /**
     * Display a listing of the resource.
     *  标签列表识图
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data=Tag::paginate(5);
        return view('admin.tag.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *  添加标签识图
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.tag.create');
    }

    /**
     * Store a newly created resource in storage.
     *  保存新增的数据
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(TagRequest $tagRequest,Tag $tag)
    {
        $tag->create($tagRequest->all());
        flash('标签添加成功')->overlay();
        return redirect('/admin/tag');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *  修改识图
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $model=Tag::find($id);
        return view('admin.tag.edit',compact('model'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $model=Tag::find($id);
        $model['name']=$request->input('name');
        $model->save();
        flash('标签修改成功')->overlay();
        return redirect('/admin/tag');
    }

    /**
     * Remove the specified resource from storage.
     *  删除识图
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        Tag::destroy($id);
        return $this->success('删除成功');
    }
}
